package com.huatai.saas.controller;

import com.huatai.common.api.R;
import com.huatai.saas.dto.BackChunkDto;
import com.huatai.saas.service.FileChunkService;
import com.huatai.saas.vo.CheckChunkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @BelongsProject: nanming-saas
 * @BelongsPackage: com.huatai.saas.controller
 * @Author: hecaiy
 * @CreateTime: 2024-04-11  19:05
 * @Description: TODO
 * @Version: 1.0
 */
@Api(description = "后台文件管理", tags = "后台文件管理")
@RestController
@RequestMapping("backGroud/file")
public class BackFileController {

	@Autowired
	private FileChunkService fileChunkService;

	/**
	 * 文件分片上传
	 * @param chunk
	 * @param response
	 * @return
	 */
	@ApiOperation(value = "文件分片上传", notes = "文件分片上传")
	@PostMapping("/upload")
	public R<Integer> postFileUploadMinio(@RequestBody BackChunkDto chunk, HttpServletResponse response) {
		if (chunk.getFile().isEmpty()) {
			throw new RuntimeException("文件不能为空");
		}
		return R.data(fileChunkService.postFileUploadMinio(chunk, response));
	}

	@ApiOperation(value = "检查文件上传状态", notes = "检查文件上传状态")
	@RequestMapping("/upload")
	public R<CheckChunkVO> getFileUpload(@RequestBody BackChunkDto chunk, HttpServletResponse response) {
		return R.data(fileChunkService.getFileUpload(chunk, response));
	}

	@ApiOperation(value = "合并文件", notes = "合并文件")
	@RequestMapping("/merge")
	public void merge(@RequestBody BackChunkDto chunk) throws Exception {
		fileChunkService.merge(chunk);
	}


}
